#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author: Bartosz Bubak <bartosz.bubak@gmail.com>
'''
import wx
import sys
from plotGenerator import *

__version__ = '0.1.1'
__author__ = 'Bartosz Bubak'

class mainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='Plot Generator v..' + __version__, size=(500, 300))

        font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        font.SetPointSize(9)

        mainPanel = wx.Panel(self)
        mainPanel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

        vbox = wx.BoxSizer(wx.VERTICAL)
        
        inputBox = wx.BoxSizer(wx.HORIZONTAL)
        st1 = wx.StaticText(mainPanel, label='Parse text')
        st1.SetFont(font)
        inputBox.Add(st1, flag=wx.RIGHT, border=8)
        self.tc = wx.TextCtrl(mainPanel, value = '${kto.txt} ${kogo.txt} ${co_robi.txt} ${dlaczego.txt}')
        
        inputBox.Add(self.tc, proportion=1)
        button1 = wx.Button(mainPanel, label="Generate")
        button1.Bind(wx.EVT_BUTTON, self.OnGenerateButtonClicked)
        inputBox.Add(button1)
        vbox.Add(inputBox, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, border=10)

        vbox.Add((-1, 10))
        
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)
        self.outBox = wx.TextCtrl(mainPanel, style=wx.TE_MULTILINE)
        hbox3.Add(self.outBox, proportion=1, flag=wx.EXPAND)
        vbox.Add(hbox3, proportion=1, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, 
            border=10)

        vbox.Add((-1, 25))

        mainPanel.SetSizer(vbox)
        self.tc.SetSelection(0,1)

        self.Show()

    def OnGenerateButtonClicked(self, event):
        tekst = self.tc.GetValue() + '\n'
        pg = plotGenerator()
        self.outBox.AppendText(pg.parseLine(tekst))
        
    def OnKeyDown(self, event):
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_ESCAPE:
            ret  = wx.MessageBox('Are you sure to quit?', 'Question', wx.YES_NO | wx.NO_DEFAULT, self)
            if ret == wx.YES:
                self.Close()

app = wx.App(redirect = False)
frame = mainFrame()
#frame.Show()
app.MainLoop()